package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-07-24
 * Time: 14:48
 */
class Counter {
    public int count = 0;
    synchronized public void increase() {
        count+=1;
    }
}
public class Demo11 {
    public static void main(String[] args) throws InterruptedException {
        long time = System.currentTimeMillis();
        Counter counter = new Counter();
        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                counter.increase();
            }
        });
        Thread thread2 = new Thread(()-> {
            for (int i = 0; i < 50000; i++) {
                counter.increase();
            }
        });
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.println(counter.count);
        long time2 = System.currentTimeMillis();
        System.out.println(time2 - time);
    }
}
